package com.hypo.controller;



import com.hypo.annotation.LogOperation;
import com.hypo.pojo.Clazz;
import com.hypo.pojo.QueryString;
import com.hypo.pojo.Result;
import com.hypo.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    /**
     * 查询全部
     */
    @GetMapping("/list")
    public Result findAll(){
        List<Clazz> all = clazzService.findAll();
        return Result.success(all);
    }

    /**
     * 添加
     */
    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        int add = clazzService.add(clazz);
        return Result.success();
    }

    /**
     * 分页查询
     */
    @GetMapping
    public Result page(QueryString queryString){
        return Result.success(clazzService.page(queryString));
    }

    /**
     * 根据Id
     */
    @DeleteMapping("{id}")
    public Result delClass(@PathVariable Integer id){
        return Result.success(clazzService.delClass(id));
    }

    /**
     * id查询回显
     */
    @LogOperation
    @GetMapping("{id}")
    public Result getById(@PathVariable Integer id){
        return Result.success(clazzService.getById(id));
    }

    /**
     * 修改
     */
    @PutMapping
    public Result modify(@RequestBody Clazz clazz){
        return Result.success(clazzService.modify(clazz));
    }
}
